package com.c6906.vdam.das.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: taohuiqi @Date: 2024/06/15/14:53 @Description:knife4j配置信息
 */
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {

    @Bean
    public Docket adminApiConfig() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("token").description("用户token").defaultValue("").modelRef(new ModelRef("string"))
                .parameterType("header").required(false).build();
        pars.add(tokenPar.build());
        // 添加head参数end

        Docket adminApi = new Docket(DocumentationType.SWAGGER_2).groupName("das").apiInfo(adminApiInfo()).select()
                // 只显示admin路径下的页面
                .apis(RequestHandlerSelectors.basePackage("com.c6906.vdam.das")).paths(PathSelectors.any()).build()
                .globalOperationParameters(pars);
        return adminApi;
    }

    private ApiInfo adminApiInfo() {

        return new ApiInfoBuilder().title("DAS服务-API文档").description("本文档描述了DAS服务接口定义").version("V1.0")
                .contact(new Contact("taohuiqi", "http://localhost:11000/das/doc.html", "admin@das.com")).build();
    }
}
